<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./lib/vue-2.5.9.js"></script>
  <!-- 1. 导入路由JS文件 -->
  <script src="./lib/vue-router-v3.0.1.js"></script>

  <style>
    .router-link-active {
      color: red;
      font-weight: bold;
      font-style: italic;
      font-size: 20px;
      text-decoration: underline;
    }

    .my-active {
      color: orange;
      font-size: 30px;
    }

    .v-enter,
    .v-leave-to {
      opacity: 0;
      transform: translateX(100px);
    }

    .v-enter-active,
    .v-leave-active {
      transition: all 0.3s ease;
      position: absolute;
    }
  </style>
</head>

<body>
  <div id="app">

    <!-- 路由链接 -->
    <router-link to="/login/10/zs">登录</router-link>
    <router-link to="/reg">注册</router-link>

    <!-- 展示路由组件的容器 -->
    <transition>
      <router-view></router-view>
    </transition>

  </div>

  <script>

    // 2. 定义两个要切换的组件
    const login = {
      template: '<h3>登录组件 --- {{ $route.params.id }} --- {{ $route.params.name }}</h3>',
      created() {
        console.log(this)
      }
    }
    const reg = {
      template: '<h3>注册组件</h3>'
    }

    // 3. 创建路由对象
    const router = new VueRouter({
      routes: [ // 路由规则的数组
        // { path: '/', component: login },
        { path: '/', redirect: '/login' },
        { path: '/login/:id/:name', component: login },
        { path: '/reg', component: reg }
      ],
      linkActiveClass: 'my-active' // 配置默认被 选中路由的高亮类名的 ， 默认类名为 router-link-active
    })

    // 创建 Vue 实例，得到 ViewModel
    var vm = new Vue({
      el: '#app',
      data: {},
      methods: {},
      router // 4. 把路由对象，挂载到 VM 实例上
    });
  </script>
</body>

</html>